home *** CD-ROM | disk | FTP | other *** search
- /* DriverDebugSupport.c */
- /*
- * DriverDebugSupport.c
- * Copyright © 1994 Apple Computer Inc. All rights reserved.
- */
- /* .___________________________________________________________________________________.
- | These routines are marginally useful. They were thrown together and should be |
- | redone for a production system. As debugging progressed, I relied more and more |
- | on looking at logging information. Crashing into MacsBug at any error is really |
- | only useful for the initial stages of development. |
- | |
- | Most of this file is compiled only if USE_LOG_LIBRARY is non-zero. |
- .___________________________________________________________________________________.
- */
- #include "NCRDriverPrivate.h"
-
- #if USE_LOG_LIBRARY
- /*
- * We don't trace these.
- */
- void
- CheckStatus(
- OSErr value,
- ConstStr255Param message
- )
- {
- if (value != noErr)
- LogStatusString(value, message);
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Logging subroutines
- */
- void LogMemory(
- register void *areaAddress,
- register Size byteCount
- )
- {
- unsigned long startIndex;
- unsigned long endIndex;
- unsigned long i;
- Str255 work;
-
- /*
- * WriteLogEntry writes up to 40 characters. This is organized as
- * Start Index 3
- * 4 groups of 4 bytes: 4 * (8 + 1)
- * One left over for good luck.
- */
- WriteLogEntry(GLOBAL.logRecordPtr, 'LMem',
- LogFormat3(kLogFormatAddress, kLogFormatUnsigned, kLogFormatString),
- (unsigned long) areaAddress, byteCount, "\pLog Memory"
- );
- if (byteCount > 64)
- byteCount = 64;
- for (startIndex = 0; startIndex < byteCount; startIndex += 16) {
- endIndex = startIndex + 16;
- if (endIndex > byteCount)
- endIndex = byteCount;
- work[0] = 0;
- AppendHexLeadingZeros(work, startIndex, 3);
- for (i = startIndex; i < endIndex; i++) {
- if ((i & 0x03) == 0x00)
- AppendChar(work, ' ');
- AppendHexLeadingZeros(work, ((UInt8 *) areaAddress)[i], 2);
- }
- WriteLogEntry(GLOBAL.logRecordPtr, 'LMem', LogStringFormat, work);
- }
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Output a string of hex digits with leading zeros. May not move memory. Note that
- * "digits" is the field width, not the number of hex bytes. Debug only.
- */
- void
- AppendHexLeadingZeros(
- StringPtr result,
- unsigned long value,
- short fieldWidth
- )
- {
- if (--fieldWidth > 0)
- AppendHexLeadingZeros(result, value >> 4, fieldWidth);
- value &= 0x0F;
- AppendChar(result,
- (value < 10)
- ? value + '0'
- : (value + ('A' - 10))
- );
- }
-
-
- void
- AppendUnsigned(
- StringPtr result,
- unsigned long value
- )
- {
- if (value >= 10)
- AppendUnsigned(result, value / 10);
- AppendChar(result, (value % 10) + '0');
- }
-
- #endif /* LOG_LIBRARY */
-
- /*
- * This is always present - it's needed for PublishInitFailureMsg.c
- */
- void
- AppendSigned(
- StringPtr result,
- signed long value
- )
- {
- if (value < 0) {
- AppendChar(result, '-');
- value = (-value);
- }
- AppendUnsigned(result, (unsigned long) value);
- }
-
-
-